/**
 * @ClassName Offer58
 * @Description 剑指 Offer 58 - II. 左旋转字符串
 * @Author clockTown
 * @Date 2021/8/15 15:42
 * @Version 1.0
 */
class Offer58II {
}

/**
 * v0 使用StringBuilder进行拼接
 */
class Offer58IIV0 {
    public String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        StringBuilder res = new StringBuilder();
        for (int i = n; i < chars.length; i++) {
            res.append(chars[i]);
        }
        for (int i = 0; i < n; i++) {
            res.append(chars[i]);
        }
        return res.toString();
    }
}

/**
 * v1 字符串切片
 */
class Offer58IIV1 {
    public String reverseLeftWords(String s, int n) {
        return s.substring(n) + s.substring(0, n);
    }
}

/**
 * v2 v0版本使用求余运算简化代码
 */
class Offer58IIV2{
    public String reverseLeftWords(String s, int n) {
        StringBuilder res = new StringBuilder();
        for (int i = n; i < n + s.length(); i++) {
            res.append(s.charAt(i % s.length()));
        }
        return res.toString();
    }
}